package com.r_z.service.impl;

import com.r_z.entity.Repertory;
import com.r_z.entity.StoragesDetails;
import com.r_z.mapper.RepertoryMapper;
import com.r_z.service.RepertoryService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 任俊杰
 * @version 1.0
 * @date 2023/5/30
 */
@Service
public class RepertoryImpl implements RepertoryService {
    //导入mapper接口
    @Resource
    RepertoryMapper repertoryMapper;

    /**
     * 查询全部库存
     * @param page 当前页
     * @param limit 每页显示数
     * @param productName 商品名称
     * @return repertoryList 库存集合
     */
    @Override
    public List<Repertory> selectRepertory(Integer page,Integer limit,String productName) {
        int pages=(page-1)*limit;
        List<Repertory> repertoryList = repertoryMapper.selectRepertory(pages,limit,where(productName));
        return repertoryList;
    }

    /**
     * 拼接条件
     * @param productName 库存实体
     * @return 条件
     */

    public String where(String productName) {
        StringBuffer where = new StringBuffer();
        if (productName!=null && !productName.equals("")){
            where.append(" and productName LIKE '%"+productName+"%'");
        }
        System.out.println(where);
        return where.toString();
    }

    /**
     * 查询条数
     * @return 条数
     */
    @Override
    public int getTotal(String productName) {
        return repertoryMapper.getTotal(where(productName));
    }

    /**
     * 库存 增加
     * @param repertory 库存实体
     * @return 返回一个标识 i>=1则成功 反之失败
     */
    @Override
    public int addRepertory(Repertory repertory) {
        return repertoryMapper.addRepertory(repertory);
    }
    /**
     * 库存 修改
     * @param repertory 库存实体
     * @return 返回一个标识 i>=1则成功 反之失败
     */
    @Override
    public int updateRepertory(Repertory repertory) {
        return repertoryMapper.updateRepertory(repertory);
    }

    /**
     * 库存 删除
     * @param repertory 库存id
     * @return 返回一个标识 i>=1则成功 反之失败
     */
    @Override
    public int deleteRepertory(Repertory repertory) {
        return repertoryMapper.deleteRepertory(repertory);
    }

    /**
     * 查入库商品详情的数量
     * @return 商品数量
     */
    public List<StoragesDetails>getStorageCount(){
        List<StoragesDetails> storageCount = repertoryMapper.getStorageCount();
        return storageCount;
    }
}
